package com.wn.netty.heartbeat;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.timeout.IdleStateEvent;

/**
 * @FileName: SimpleHeartbeatHandler
 * @Description: TODO
 * @Author: MaWenHao
 * @Created: 2020/8/5 - 17:38
 * @Version: V1.0
 * @Company: 东方微银科技（北京）有限公司
 */
public class SimpleHeartbeatHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        if (evt instanceof IdleStateEvent) {
            IdleStateEvent event = (IdleStateEvent) evt;
            String msg = "";
            switch (event.state()) {
                case READER_IDLE:
                    msg = "读空闲";
                    break;
                case WRITER_IDLE:
                    msg = "写空闲";
                    break;
                default:
                    msg = "读写空闲";
            }
            System.out.println("------------------" + msg);
            ctx.channel().close();
        }
    }
}
